package com.project.mapper.provide;

import com.project.bean.RoomBean;
import org.apache.ibatis.annotations.Param;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class RoomProvide {
    public String findByItem(Map map){
        String sql ="SELECT r.*,COUNT(s.`pk_studentId`) num FROM t_room r left join t_student s on s.`fk_roomId`=r.`pk_roomId` where 1=1 ";
        if(map.get("address")!=null){
            sql += "and r.`r_address` like '%"+map.get("address")+"%'";
        }
        if(map.get("type")!=null && !map.get("type").equals("不限")){
            sql += "and r.`r_type` LIKE '%"+map.get("type")+"%' ";
        }
        if(map.get("repair")!=null && !map.get("repair").equals("不限")){
            sql += "and r.`r_state`= '"+map.get("startDate")+"' ";
        }
        sql += "GROUP BY r.`pk_roomId` ";
        if(map.get("state")!=null && map.get("state").equals("可住房间")){
            sql += "HAVING num < r.`r_canInLive`";
        }
        return sql;
    }
}
